package com.lwc.cfdns.pojo.security;

import com.lwc.cfdns.enums.ResultCode;
import com.lwc.cfdns.utils.ServletUtils;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Security 授权失败处理器
 *
 * @author luwc
 * @title AccessDeniedHandlerImpl
 * @description
 * @time 2023/5/11 11:25:27
 * @version: 1.0
 */
@Component
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {
    /**
     * 处理器
     *
     * @param request
     * @param response
     * @param accessDeniedException
     * @return void
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/11 11:27:25
     */
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        ServletUtils.renderString(response, ResultCode.AUTH_FORBIDDEN);
    }
}
